package cn.rengy.util;

import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

@Slf4j
public class SystemUtil {
    private SystemUtil(){}

    public static void logAppArgs(String[] args ){
        StringBuilder sb=new StringBuilder();
        for(String arg:args){
            sb.append(arg).append("\n");
        }
        log.info("\n应用程序参数: \n{}",sb.toString());
    }
    public static void logProperties(){
        Properties properties=System.getProperties();
        Iterator<Map.Entry<Object, Object>> it=properties.entrySet().iterator();
        StringBuilder sb=new StringBuilder();
        while (it.hasNext()){
            Map.Entry<Object, Object> e=  it.next();
            System.out.println(e.getKey()+":"+e.getValue());
            sb.append(e.getKey().toString()).append("=").append(e.getValue().toString())
                    .append("\n");
        }
        log.info("\nJVM系统属性: \n{}",sb.toString());
    }
    public static void logEnv(){
        Map<String,String> env=System.getenv();
        Iterator<Map.Entry<String, String>> it=env.entrySet().iterator();
        StringBuilder sb=new StringBuilder();
        while (it.hasNext()){
            Map.Entry<String, String> e=  it.next();
            sb.append(e.getKey()).append("=").append(e.getValue())
                    .append("\n");
        }
        log.info("\n系统环境变量: \n{}",sb.toString());
    }
}
